package com.hualan.zhsq.service.impl.car;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.car.PayVehicle;
import com.hualan.zhsq.mapper.car.PayVehicleMapper;
import com.hualan.zhsq.service.car.PayVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName PayVehicleServiceImpl
 * @Description TODO
 * @Author ZheRan
 * @Date 2025年08月08日 下午2:11
 * @Version 1.0
 */
@Service("payVehicleService")
public class PayVehicleServiceImpl implements PayVehicleService {
    @Autowired
    private PayVehicleMapper payVehicleMapper;

    @Override
    public Map<String, Object> payVehicle(Integer pageNum, Integer pageSize, PayVehicle payVehicle) {
        Page<PayVehicle> page = new Page<>(pageNum, pageSize);
        Page<PayVehicle> payVehiclePage = payVehicleMapper.selectAllPage(page, payVehicle);
        Map<String, Object> map = new HashMap<>();

        long total = payVehiclePage.getTotal();
        long size = payVehiclePage.getSize();
        List<PayVehicle> list = payVehiclePage.getRecords();

        map.put("total", total);
        map.put("size", size);
        map.put("list", list);
        return map;
    }

    @Override
    public int add(PayVehicle entity) {
        return payVehicleMapper.insert(entity);
    }

    @Override
    public int edit(PayVehicle entity) {
        return payVehicleMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return payVehicleMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return payVehicleMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<PayVehicle> find() {
        return payVehicleMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, PayVehicle entity) {
        Page<PayVehicle> page = new Page<>(pageNum, pageSize);
        QueryWrapper<PayVehicle> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del", 0);
        Page<PayVehicle> payVehiclePage = payVehicleMapper.selectPage(page,queryWrapper);
        Map<String, Object> map = new HashMap<>();
        long total = payVehiclePage.getTotal();
        long size = payVehiclePage.getSize();
        List<PayVehicle> list = payVehiclePage.getRecords();
        map.put("total", total);
        map.put("size", size);
        map.put("list", list);
        return map;
    }

    @Override
    public PayVehicle findById(Integer id) {
        return payVehicleMapper.selectById(id);
    }
}
